<!--
  @file ResourceChat.vue
  @description 智能教学资源AI对话页面，支持多轮会话
  @created 2024-06-26
-->
<template>
  <div class="ai-chat-container">
    <el-input
      v-model="userInput"
      placeholder="请输入你的问题或资源描述"
      @keyup.enter="sendMessage"
      clearable
    />
    <el-button type="primary" @click="sendMessage">发送</el-button>
    <div v-if="aiReply" class="ai-reply">
      <pre>{{ aiReply }}</pre>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { adminAiChat } from '@/api/ai'

const userInput = ref('')
const aiReply = ref('')
let conversationId = '' // 会话ID

async function sendMessage() {
  if (!userInput.value) return
  const fileInfo = '' // 可拼接文件名、类型、内容摘要
  const res = await adminAiChat({
    query: userInput.value,
    file_info: fileInfo,
    conversation_id: conversationId,
    user_id: 'admin-001'
  })
  if (res.data.status === 'success') {
    aiReply.value = res.data.data.answer
    conversationId = res.data.data.conversation_id
  } else {
    aiReply.value = 'AI服务异常，请稍后重试'
  }
}
</script>

<style scoped>
.ai-chat-container { padding: 24px; }
.ai-reply { margin-top: 16px; background: #f6f8fa; padding: 12px; border-radius: 6px; }
</style> 